<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="/css/bootstrap.min.css">
<link rel="stylesheet" href="/css/laypage.css">
<script src="/js/jquery/jquery.min.js"></script>
<script src="/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
<script src="/js/jquery.validation/1.14.0/messages_zh.min.js"></script>
<style>
	input.error{
		border: 1px solid #E6594E;
	}
</style>
</head>
<body>
	  <div class="container">
	
		<form id="editUserForm">
		
		     <h4>
                  申请人：${oabuy.oaUser.userUsername}<br><br>
                  申购部门：${oabuy.oaDept.deptName}<br><br>          
                   申请日期：<input type="text" name="buyDate" id="buyDate" value ="${oabuy.buyDate}" readonly="readonly" style="border:none"><br>
               <br></h4>
		  <br/>
		   <div class="form-group">
			<label for="buyName">物品名称：</label>
			<input type="text" class="form-control" id="buyName" name="buyName" value="${oabuy.buyName}"placeholder="输入物品名称">
		  </div>
		  
		  <div class="form-group">
			<label for="buyNumber">数量：</label>
			<input type="text" class="form-control" id="buyNumber" name="buyNumber" value="${oabuy.buyNumber}"placeholder="输入数量">
		  </div>
		  
		  <div class="form-group">
			<label for="buyPrice">单价：</label>
			<input type="text" class="form-control" id="buyPrice" name="buyPrice" value="${oabuy.buyPrice}"placeholder="输入单价">
		  </div>
		  
		  <div class="form-group">
			<label for="buyUseDate">需求时间：</label>
			<input type="text" class="form-control" id="buyUseDate" name="buyUseDate"value="${oabuy.buyUseDate}" placeholder="输入需求时间">
		  </div>

		  <div class="form-group">
			<label for="buyUse">用途：</label>
			<input type="text" class="form-control" id="buyUse" name="buyUse"  value="${oabuy.buyUse}" placeholder="输入用途">
		  </div>
		  <div class="form-group">
		  <button type="button" id="saveBtn" class="btn btn-success">提交</button>
		  <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
		  </div>
		</form>
    </div>
    	<input type="hidden" name="oaDept.deptId" id="deptid" value ="${oabuy.oaDept.deptId}">
        <input type="hidden" name="oaUser.userId" id="userid" value ="${oabuy.oaUser.userId}">
        <input type="hidden" name="buyId" id="buyId" value ="${oabuy.buyId}">
                 状态：
          <select id="submitd">
              <option value="${oabuy.oaSubmit.submitId}">${oabuy.oaSubmit.submitState}</option>
              <option value="2">已完成</option>
              <option value="9">审批中</option>
              <option value="10">未通过</option>
        </select>
        
        <input type="hidden" name="oaSubmit.submitId" id="submitid" value ="1">
		<script>
			var editUser = function(){
				if(!check().form()){ 
					return;  
				}
				$.ajax({
					   type: "GET",
					   dataType: "json",
					   url: "/OaBuy/edit",
					   data: {
					 "buyId": $("#buyId").val(),
					"buyName": $("#buyName").val(),
					"buyNumber": $("#buyNumber").val(),
					"buyPrice": $("#buyPrice").val(),
					"buyUse": $("#buyUse").val(),
					"buyDate": $("#buyDate").val(),
					"buyUseDate": $("#buyUseDate").val(),
					"oaSubmit.submitId": $("#submitd").val(),
					"oaUser.userId": $("#userid").val(),
					   },
					   success: function(msg){
							$('#cancelBtn').click();			
					   }
				});
			}
			
			$('#saveBtn').on('click', function(){
				editUser();
			});
			
			$('#cancelBtn').on('click', function(){
				var index = parent.layer.getFrameIndex(window.name);
				parent.getUserPageList();
				parent.layer.close(index);
			});

			
			//校验字段是否正确 
            function check(){ 
                /*返回一个validate对象，这个对象有一个form方法，返回的是是否通过验证*/ 
                return $("#editUserForm").validate({ 
                            rules:{ 
                                username:{ 
                                    required:true
                                },
                                userage:{ 
                                    required:true                                   
                                }
                            }, 
                            messages:{ 
                                username:{ 
                                    required:""
                                },
                                userage:{ 
                                    required:""                                
                                }
                            }     
                        }); 
            } 
			
		</script> 	
	
</body>
</html>













